1
|
|
|
/* global simulatorData */ |
2
|
|
|
if (simulatorData.pagantisSimulator4x === 'enabled') { |
3
|
|
|
var simulator4xdiv = document.getElementsByClassName('mainPagantisSimulator'); |
4
|
|
|
if (simulator4xdiv.length > 0 && typeof simulator4xdiv != 'undefined') { |
5
|
|
|
simulator4xdiv[0].innerHTML = simulatorData.simulatorMessage; |
6
|
|
|
var position = simulatorData.positionSelector4x; |
7
|
|
|
if (position !== 'default') { // Move to desired class |
8
|
|
|
var desiredPosition = document.getElementsByClassName(position); |
9
|
|
|
if (desiredPosition.length > 0 && typeof desiredPosition != 'undefined') { |
10
|
|
|
desiredPosition[0].appendChild(simulator4xdiv[0]); |
11
|
|
|
} |
12
|
|
|
} |
13
|
|
|
} |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
function findPriceSelector() { |
18
|
|
|
var priceSelectors = simulatorData.priceSelector; |
19
|
|
|
if (typeof priceSelectors == 'undefined') console.log("simulator priceSelectors is undefined"); |
|
|
|
|
20
|
|
|
return priceSelectors.find(function (candidateSelector) { |
21
|
|
|
var priceDOM = document.querySelector(candidateSelector); |
22
|
|
|
return (priceDOM != null); |
|
|
|
|
23
|
|
|
}); |
24
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
function findPositionSelector() { |
28
|
|
|
var positionSelector = simulatorData.positionSelector; |
29
|
|
|
if (positionSelector === 'default') { |
30
|
|
|
positionSelector = '.pagantisSimulator'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return positionSelector; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function findQuantitySelector() { |
37
|
|
|
var quantitySelectors = simulatorData.quantitySelector; |
38
|
|
|
return quantitySelectors.find(function (candidateSelector) { |
39
|
|
|
var priceDOM = document.querySelector(candidateSelector); |
40
|
|
|
return (priceDOM != null); |
|
|
|
|
41
|
|
|
}); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function finishInterval() { |
45
|
|
|
clearInterval(window.loadingSimulator); |
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function checkSimulatorContent() { |
50
|
|
|
var simulatorLoaded = false; |
51
|
|
|
var positionSelector = findPositionSelector(); |
52
|
|
|
var pgDiv = document.querySelectorAll(positionSelector); |
53
|
|
|
if (pgDiv.length > 0 && typeof window.WCSimulatorId != 'undefined') { |
54
|
|
|
var pgElement = pgDiv[0]; |
55
|
|
|
if (pgElement.innerHTML !== '') { |
56
|
|
|
simulatorLoaded = true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
return simulatorLoaded; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function findDestinationSim() { |
63
|
|
|
var destinationSim = simulatorData.finalDestination; |
64
|
|
|
if (destinationSim === 'default' || destinationSim == '') { |
65
|
|
|
destinationSim = 'woocommerce-product-details__short-description'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return destinationSim; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function checkAttempts() { |
72
|
|
|
window.attempts = window.attempts + 1; |
73
|
|
|
return (window.attempts > 10) |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function loadSimulatorPagantis() { |
77
|
|
|
if (typeof pgSDK == 'undefined' || typeof simulatorData == 'undefined') { |
|
|
|
|
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (checkAttempts() || checkSimulatorContent()) { |
82
|
|
|
return finishInterval(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
var country = simulatorData.country; |
86
|
|
|
var locale = simulatorData.locale; |
87
|
|
|
var sdk = pgSDK; |
88
|
|
|
|
89
|
|
|
var positionSelector = findPositionSelector(); |
90
|
|
|
var priceSelector = findPriceSelector(); |
91
|
|
|
var promotedProduct = simulatorData.promoted; |
92
|
|
|
var quantitySelector = findQuantitySelector(); |
93
|
|
|
|
94
|
|
|
var simulator_options = { |
95
|
|
|
publicKey: simulatorData.public_key, |
96
|
|
|
type: eval(simulatorData.simulator_type), |
|
|
|
|
97
|
|
|
selector: positionSelector, |
98
|
|
|
itemQuantitySelector: quantitySelector, |
99
|
|
|
locale:locale, |
100
|
|
|
country: country, |
101
|
|
|
itemAmountSelector: priceSelector, |
102
|
|
|
amountParserConfig: { |
103
|
|
|
thousandSeparator: simulatorData.thousandSeparator, |
104
|
|
|
decimalSeparator: simulatorData.decimalSeparator, |
105
|
|
|
}, |
106
|
|
|
numInstalments: simulatorData.pagantisQuotesStart, |
107
|
|
|
skin: eval(simulatorData.pagantisSimulatorSkin), |
|
|
|
|
108
|
|
|
position: eval(simulatorData.pagantisSimulatorPosition), |
|
|
|
|
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
window.pgSDK = sdk; |
112
|
|
|
if (promotedProduct === 'true') { |
113
|
|
|
simulator_options.itemPromotedAmountSelector = priceSelector; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if (typeof window.pgSDK !== 'undefined') { |
|
|
|
|
117
|
|
|
window.WCSimulatorId = window.pgSDK.simulator.init(simulator_options); |
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
window.attempts = 0; |
123
|
|
|
if (simulatorData.pagantisSimulator === 'enabled') { |
124
|
|
|
window.loadingSimulator = setInterval(function () { |
125
|
|
|
loadSimulatorPagantis(); |
126
|
|
|
}, 2000); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if (simulatorData.promoted === 'true') { |
130
|
|
|
simulatorData.promotedMessage; |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|